package net.bwie.realtime.dws.log.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class CityCodeConverter {

    private static final String DATA_FILE = "D:\\2211A\\workspace\\realtime-project-22haozelin\\userProfile-realtime-project\\userProfile-realtime-dws\\src\\main\\java\\net\\bwie\\realtime\\dws\\log\\utils\\city_codes.txt";
    private static Map<String, String> cityCodeMap = new HashMap<>();

    static {
        loadCityCodeData();
    }

    private static void loadCityCodeData() {
        try (BufferedReader reader = new BufferedReader(new FileReader(DATA_FILE))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(":");
                if (parts.length == 2) {
                    String cityName = parts[0].trim();
                    String cityCode = parts[1].trim();
                    cityCodeMap.put(cityName, cityCode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getCityCode(String cityName) {
        return cityCodeMap.get(cityName);
    }

}